

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Data &mdash; Twitter Geolocation Predictor 0.1 documentation</title>
  

  
  
  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  

  

  
        <link rel="index" title="Index"
              href="../genindex.html"/>
        <link rel="search" title="Search" href="../search.html"/>
    <link rel="top" title="Twitter Geolocation Predictor 0.1 documentation" href="../index.html"/>
        <link rel="next" title="Models" href="twgeo.models.html"/>
        <link rel="prev" title="Twitter Geolocation Predictor" href="../index.html"/>
    <link href="../_static/mystyles.css" rel="stylesheet" type="text/css">


  
  <script src="../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../index.html" class="icon icon-home"> Twitter Geolocation Predictor
          

          
          </a>

          
            
            
              <div class="version">
                0.1
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">API</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="#">Data</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#module-twgeo.data.input">twgeo.data.input</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-twgeo.data.reverse_geocode">twgeo.data.reverse_geocode</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-twgeo.data.twus_dataset">twgeo.data.twus_dataset</a></li>
<li class="toctree-l2"><a class="reference internal" href="#module-twgeo.data">Module contents</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="twgeo.models.html">Models</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">Twitter Geolocation Predictor</a>
        
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
      <li>Data</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../_sources/source/twgeo.data.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="data">
<h1>Data<a class="headerlink" href="#data" title="Permalink to this headline">¶</a></h1>
<div class="section" id="module-twgeo.data.input">
<span id="twgeo-data-input"></span><h2>twgeo.data.input<a class="headerlink" href="#module-twgeo.data.input" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="twgeo.data.input.read_csv_data">
<code class="descclassname">twgeo.data.input.</code><code class="descname">read_csv_data</code><span class="sig-paren">(</span><em>csv_filename: str</em>, <em>location_column_idx: int</em>, <em>tweet_txt_column_idx: int</em><span class="sig-paren">)</span><a class="headerlink" href="#twgeo.data.input.read_csv_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Pre-process raw tweet data from a csv file. For each row, this function will:</p>
<blockquote>
<div><ol class="arabic simple">
<li>Tokenize the tweet text.</li>
<li>Limit repeated characters to a maximum of 2. For example: ‘Greeeeeetings’ becomes ‘Greetings’.</li>
<li>Perform <a class="reference external" href="https://en.wikipedia.org/wiki/Stemming">Porter stemming</a> on each token.</li>
<li>Convert each token to lower case.</li>
</ol>
</div></blockquote>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>csv_filename</strong> – </li>
<li><strong>location_column_idx</strong> – The zero-based index of the CSV column that contains the location information.
The data itself must be a discrete value (a string or integer).</li>
<li><strong>tweet_txt_column_idx</strong> – The zero-based index of the CSV column that contains the tweet text.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Tuple (preprocessed_tweets, locations)</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="module-twgeo.data.reverse_geocode">
<span id="twgeo-data-reverse-geocode"></span><h2>twgeo.data.reverse_geocode<a class="headerlink" href="#module-twgeo.data.reverse_geocode" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="twgeo.data.reverse_geocode.ReverseGeocode">
<em class="property">class </em><code class="descclassname">twgeo.data.reverse_geocode.</code><code class="descname">ReverseGeocode</code><a class="headerlink" href="#twgeo.data.reverse_geocode.ReverseGeocode" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/2/library/functions.html#object" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">object</span></code></a></p>
<p>Convenience module to find the US state and Census region from a pair of global coordinates.
This class assumes you have a Postgres PostGIS database installed locally. To setup PostGIS with US Census data,
follow the instructions <a class="reference external" href="http://postgis.net/docs/postgis_installation.html#loading_extras_tiger_geocoder/">found here</a>.</p>
<dl class="method">
<dt id="twgeo.data.reverse_geocode.ReverseGeocode.get_state_index">
<code class="descname">get_state_index</code><span class="sig-paren">(</span><em>state_abbrev</em><span class="sig-paren">)</span> &#x2192; int<a class="headerlink" href="#twgeo.data.reverse_geocode.ReverseGeocode.get_state_index" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the integer value of the given state.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>state_abbrev</strong> – Example: ‘FL, NY’</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="twgeo.data.reverse_geocode.ReverseGeocode.get_state_region">
<code class="descname">get_state_region</code><span class="sig-paren">(</span><em>state_abbrev</em><span class="sig-paren">)</span> &#x2192; int<a class="headerlink" href="#twgeo.data.reverse_geocode.ReverseGeocode.get_state_region" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the integer value of the Census region of the given state.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>state_abbrev</strong> – Example: ‘FL, NY’</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="twgeo.data.reverse_geocode.ReverseGeocode.get_state_region_name">
<code class="descname">get_state_region_name</code><span class="sig-paren">(</span><em>state_abbrev</em><span class="sig-paren">)</span> &#x2192; str<a class="headerlink" href="#twgeo.data.reverse_geocode.ReverseGeocode.get_state_region_name" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the name of the Census region of a given state.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>state_abbrev</strong> – Example: ‘FL, NY’</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="twgeo.data.reverse_geocode.ReverseGeocode.reverse_geocode_state">
<code class="descname">reverse_geocode_state</code><span class="sig-paren">(</span><em>location</em><span class="sig-paren">)</span> &#x2192; str<a class="headerlink" href="#twgeo.data.reverse_geocode.ReverseGeocode.reverse_geocode_state" title="Permalink to this definition">¶</a></dt>
<dd><p>Find the corresponding US state of a given pair of coordinates.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>location</strong> – A tuple containing the (latitude, longitude)</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The corresponding state abbreviation. Example: ‘FL, NY’</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-twgeo.data.twus_dataset">
<span id="twgeo-data-twus-dataset"></span><h2>twgeo.data.twus_dataset<a class="headerlink" href="#module-twgeo.data.twus_dataset" title="Permalink to this headline">¶</a></h2>
<p>Built-in dataset of ~450K US based users.</p>
<dl class="function">
<dt id="twgeo.data.twus_dataset.load_region_data">
<code class="descclassname">twgeo.data.twus_dataset.</code><code class="descname">load_region_data</code><span class="sig-paren">(</span><em>size='large'</em><span class="sig-paren">)</span><a class="headerlink" href="#twgeo.data.twus_dataset.load_region_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Training samples labeled with the corresponding US Census Region.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Param:</th><td class="field-body">size: ‘micro’: 10,000 samples
‘small’: 50,000 samples, ‘mid’: 100,000 samples, ‘large’: 410,000 samples.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Tuple(x_train, y_train, x_dev, y_dev, x_test, y_test)</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="twgeo.data.twus_dataset.load_state_data">
<code class="descclassname">twgeo.data.twus_dataset.</code><code class="descname">load_state_data</code><span class="sig-paren">(</span><em>size='large'</em><span class="sig-paren">)</span><a class="headerlink" href="#twgeo.data.twus_dataset.load_state_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Training samples labeled with the corresponding US State.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Param:</th><td class="field-body">size: ‘micro’: 10,000 samples
‘small’: 50,000 samples, ‘mid’: 100,000 samples, ‘large’: 410,000 samples.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Tuple(x_train, y_train, x_dev, y_dev, x_test, y_test)</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="module-twgeo.data">
<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-twgeo.data" title="Permalink to this headline">¶</a></h2>
</div>
</div>


           </div>
           <div class="articleComments">
            
           </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="twgeo.models.html" class="btn btn-neutral float-right" title="Models" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="../index.html" class="btn btn-neutral" title="Twitter Geolocation Predictor" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2017, Javier Matias.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../',
            VERSION:'0.1',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../_static/jquery.js"></script>
      <script type="text/javascript" src="../_static/underscore.js"></script>
      <script type="text/javascript" src="../_static/doctools.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

  

  
  
    <script type="text/javascript" src="../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>